/**
 * 代理商管理   银行卡管理
 */
<template>
  <div>
    <!-- 面包屑导航 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>银行卡管理</el-breadcrumb-item>
    </el-breadcrumb>
    <!-- 搜索筛选 -->
    <el-form :inline="true" :model="formInline" class="user-search">
      <el-form-item label="搜索：">
        <el-input size="small" v-model="formInline.deptName" placeholder="银行卡号"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button size="small" type="primary" icon="el-icon-search" @click="search">搜索</el-button>
        <el-button size="small" type="primary" icon="el-icon-plus" @click="openDialog">添加</el-button>
      </el-form-item>
    </el-form>
    <!--列表-->
    <el-table size="small" :data="listData" highlight-current-row v-loading="loading" border element-loading-text="拼命加载中" style="width: 100%;">
      <el-table-column align="center" type="selection" width="60">
      </el-table-column>
      <el-table-column sortable prop="phone" label="手机号" width="200">
      </el-table-column>
      <el-table-column sortable prop="cardnumber" label="银行卡号" width="300">
      </el-table-column>
      <el-table-column sortable prop="bankname" label="银行名称" width="200">
      </el-table-column>
      <el-table-column  label="操作" min-width="300">
        <template slot-scope="scope">
			    <el-button size="mini" type="danger" @click="handleEdit(scope.$index, scope.row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页组件 -->
    <Pagination v-bind:child-msg="pageparm" @callFather="callFather"></Pagination>
    <!-- 提现页面 -->
		<el-dialog class="poup" title="添加银行" :visible.sync="editFormVisible" width="30%" @click="closeDialog">
			<el-form label-width="120px" :model="cardObj" :rules="rules" ref="cardObj">
        <el-form-item label="银行卡号" prop="cardnumber">
          <el-input size="small" v-model="cardObj.cardnumber" auto-complete="off" placeholder="请输入银行卡号"></el-input>
        </el-form-item>
        <el-form-item label="银行名称" prop="bankname">
          <el-input size="small" v-model="cardObj.bankname" auto-complete="off" placeholder="请输入银行名称"></el-input>
        </el-form-item>
				<el-form-item label="手机号" prop="phone">
          <el-input size="small" v-model="cardObj.phone" auto-complete="off" placeholder="请输入手机号"></el-input>
        </el-form-item>
			</el-form>
			<div slot="footer" class="dialog-footer">
				<el-button size="small" @click="closeDialog">取消</el-button>
				<el-button size="small" type="primary" :loading="loading" class="title" @click="addBankCard">保存</el-button>
			</div>
		</el-dialog>
  </div>
</template>

<script>
import { getCardList, addCard, removeCard } from '../../api/userMG'
import Pagination from '../../components/Pagination'
export default {
  data() {
    return {
      loading: false, //是显示加载
      editFormVisible: false, //控制添加银行卡页面显示与隐藏
      formInline: {
        page: 1,
        pagenum: 10,
		    adminstratorID: JSON.parse(localStorage.getItem('userdata')).ID,
      },
      cardObj:{
        cardnumber: '',
        phone: '',
        bankname: ''
      },//添加银行卡输入信息
      // rules表单验证
			rules: {
				cardnumber: [{ required: true, message: '请输入银行卡号', trigger: 'blur' }],
				phone: [{ required: true, message: '请输入手机号', trigger: 'blur' }],
        bankname: [{ required: true, message: '请输入银行名称', trigger: 'blur' }]
			},
      listData: [], //用户数据
      // 分页参数
      pageparm: {
        currentPage: 1,
        pageSize: 10,
        total: 10
      }
    }
  },
  // 注册组件
  components: {
    Pagination
  },
  /**
   * 数据发生改变
   */

  /**
   * 创建完毕
   */
  created() {
    this.getdata(this.formInline)
  },

  /**
   * 里面的方法只有被调用才会执行
   */
  methods: {
    // 获取列表
    getdata(parameter) {
      this.loading = true
      getCardList(parameter).then(res => {
          this.loading = false
           this.$message({
              type: 'info',
              message: res.message
            })
            this.listData = res.date;
            // 分页赋值
            // this.pageparm.currentPage = this.formInline.page
            // this.pageparm.pageSize = this.formInline.limit
            this.pageparm.total = res.count
        }).catch(err => {
          this.loading = false
          this.$message.error('菜单加载失败，请稍后再试！')
        })
    },
    // 分页插件事件
    callFather(parm) {
      this.formInline.page = parm.currentPage
      this.formInline.pagenum = parm.pageSize
      this.getdata(this.formInline)
    },
    // 搜索事件
    search() {
      this.getdata(this.formInline)
    },
    // 关闭提现弹出框
		closeDialog() {
			this.editFormVisible = false;
		},
    //显示提现弹出框
		openDialog: function(index) {
			this.editFormVisible = true;
		},
    // 添加银行卡
    addBankCard(){
      addCard(this.cardObj).then(res => {
        this.cardObj.cardnumber='';
        this.cardObj.phone='';
        this.closeDialog();
        this.$message({
          type: 'success',
          message: '添加银行卡成功'
        })
        this.getdata(this.formInline)
      }).catch(err => {
        this.loading = false
      })
    },
    // 删除银行卡
    handleEdit: function(index, row) {
      this.$confirm('确定要删除吗?', '信息', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
          let parameter={cardID:row.ID};
          removeCard(parameter).then(res => {
            this.getdata(this.formInline)
          }).catch(err => {
            this.loading = false
          })
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          })
        })
    },
  }
}
</script>

<style scoped lang="less">
.user-search {
  margin-top: 20px;
}
.userRole {
  width: 100%;
}
.avatar {
	width: 80px;
	height: 80px;
	display: block;
}
.avatar-uploader {
	.el-upload {
		border: 1px dashed #8c939d;
		border-radius: 6px;
		cursor: pointer;
		position: relative;
		overflow: hidden;
	}
	.el-upload:hover {
		border-color: #409eff;
	}
}
.avatar-uploader-icon {
	border: 1px dashed #8c939d;
	font-size: 28px;
	color: #8c939d;
	width: 80px;
	height: 80px;
	line-height: 80px;
	text-align: center;
}
</style>

 